package com.doit.day01;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

public class _08_往表里面put数据 {
    public static void main(String[] args) throws IOException {
        Configuration conf = HBaseConfiguration.create();
        //设置参数
        conf.set("hbase.zookeeper.quorum","linux01:2181,linux02:2181,linux03:2181");
        //创建连接对象
        Connection conn = ConnectionFactory.createConnection(conf);
        //获取连接对象
        Admin admin = conn.getAdmin();

        //table对象，这个对象就是用来对于表里面数据的操作
        Table table = conn.getTable(TableName.valueOf("test:teacher"));

        //往里面放数据 rowkey 列族对应的列，还有列的值
        Put put = new Put("rowkey002".getBytes(StandardCharsets.UTF_8));
        put.addColumn("base_info".getBytes(),"name".getBytes(),"xingge".getBytes());
        put.addColumn("base_info".getBytes(),"age".getBytes(),"40".getBytes());
        put.addColumn("base_info".getBytes(),"gender".getBytes(),"male".getBytes());
        put.addColumn("extra_info".getBytes(),"girlfriend".getBytes(),"jinlian".getBytes());
        put.addColumn("extra_info".getBytes(),"boyfriend".getBytes(),"kunkun".getBytes());
        put.addColumn("extra_info".getBytes(),"address".getBytes(),"dongbei".getBytes());

        Put put1 = new Put("rowkey003".getBytes(StandardCharsets.UTF_8));
        put1.addColumn("base_info".getBytes(),"name".getBytes(),"fangjie".getBytes());
        put1.addColumn("base_info".getBytes(),"age".getBytes(),"18".getBytes());
        put1.addColumn("base_info".getBytes(),"gender".getBytes(),"female".getBytes());
        put1.addColumn("extra_info".getBytes(),"girlfriend".getBytes(),"baby".getBytes());
        put1.addColumn("extra_info".getBytes(),"boyfriend".getBytes(),"wuyifan".getBytes());
        put1.addColumn("extra_info".getBytes(),"address".getBytes(),"dongbei".getBytes());

        Put put2 = new Put("rowkey004".getBytes(StandardCharsets.UTF_8));
        put2.addColumn("base_info".getBytes(),"name".getBytes(),"taoge".getBytes());
        put2.addColumn("base_info".getBytes(),"age".getBytes(),"42".getBytes());
        put2.addColumn("base_info".getBytes(),"gender".getBytes(),"male".getBytes());
        put2.addColumn("extra_info".getBytes(),"girlfriend".getBytes(),"tangyan".getBytes());
        put2.addColumn("extra_info".getBytes(),"boyfriend".getBytes(),"xingge".getBytes());
        put2.addColumn("extra_info".getBytes(),"address".getBytes(),"changsha".getBytes());

        Put put3 = new Put("rowkey005".getBytes(StandardCharsets.UTF_8));
        put3.addColumn("base_info".getBytes(),"name".getBytes(),"najie".getBytes());
        put3.addColumn("base_info".getBytes(),"age".getBytes(),"20".getBytes());
        put3.addColumn("base_info".getBytes(),"gender".getBytes(),"female".getBytes());
        put3.addColumn("extra_info".getBytes(),"girlfriend".getBytes(),"fangjie".getBytes());
        put3.addColumn("extra_info".getBytes(),"boyfriend".getBytes(),"taoge".getBytes());
        put3.addColumn("extra_info".getBytes(),"address".getBytes(),"shandong".getBytes());

        ArrayList<Put> puts = new ArrayList<>();
        puts.add(put1);
        puts.add(put2);
        puts.add(put3);
        puts.add(put);

        //往那个表里面put数据
        table.put(puts);





    }
}
